/*
 * main.c
 *
 *  Created on: Mar 5, 2012
 *      Author: lin
 */
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/uio.h>
#include "def/defs.h"

#include "concurrent/c_array_queue.h"
#include "util/util_time.h"
#include "clog/clogger.h"
#include "util/util_string.h"

#include <pthread.h>
#include <unistd.h>
#include "def/status.h"
#include "io/io.h"

const int* get(void) {
    int* i = malloc(sizeof(int));
    return i;
}
complex_ele_t eles[3];
void init(void) {
    int i = 10;
    complex_ele_t u;
    u.u64 = 1;
    eles[0] = u;
    u.s64 = -1;
    eles[1] = u;
    u.ptr = &i;
    eles[2] = u;
}

void test_c_array_queue(void) {
    c_array_queue_t *q = c_array_queue_new1(100);

    for (int i = 0; i < 100; i++) {
        assert(c_array_queue_eq_u64(q, i));
    }

    for (int i = 0; i < 100; i++) {
        uint64_t u64;
        assert(c_array_queue_dq_u64(q, &u64));
        assert(u64 == i);
    }

    for (int i = 0; i > -100; i--) {
        assert(c_array_queue_eq_s64(q, i));
    }

    for (int i = 0; i > -100; i--) {
        int64_t s64;
        assert(c_array_queue_dq_s64(q, &s64));
        assert(s64 == i);
    }

}

void tostring(char* buf, int len) {
    printf("%s\n", buf);
    buf[0] = 'b';
    int a = snprintf(buf, len, "%s", "cacc");
    printf("%d", a);

//    *buf = "bbb";
}
#define test_va0(...) printf(__VA_ARGS__)
#define test_va1(...) test_va0(__VA_ARGS__)

static void test_valist(const char* str, ...) {
    va_list va;
    va_start(va, str);
    vprintf("cc%d", va);
    va_end(va);
}
#define test_level(level) printf("%d \n",level);
void thread_run(void) {
    while (1) {
        perror("run ...");
        sleep(1);
    }
}
int main(void) {

    test_va0("test va0");
    test_va1("test va1");

    test_va0("test va0%s", "va0");
    test_va1("test va1%s", "va1");
    clog_init();
    clog_logger_t *log = clog_logger_get0("test", CLOG_L_ALL);

    char buf[1024];
//    clog_logger_tostring(log,buf,1024);
//    printf("%s\n",buf);

    clog_logger_t *root = clog_root_logger_get();
    clog_logger_to_string(root, buf, 1024);
    printf("%s\n", buf);

    clog_logger_list_string(buf, 1024);
    printf("%s\n", buf);

    clog_log0(log, CLOG_L_INFO, "log0%s", "aa");
    clog_log1(log, CLOG_L_INFO, "log1");

    clog_trace0(log, "trace0");

//    int rt = io_mkdir("/home/lin/temp/....");
    int rt = io_rmdir("/home/lin/temp/svn");
    printf("%d,%s\n", rt, strerror(rt));
    printf("ok\n");
    return 0;
}
